<template>
  <div class="cityAlarmTable-root">
    <formTitleVue
      title="报警预警分布"
      :selectOptions="selectOptions"
    />
    <el-table
      :data="tableData"
      class="table"
      height="30vh"
      border
      style="width: 100%">
      <el-table-column
        prop="city"
        label="地区">
        <template slot="header" slot-scope="scope">
          <span style="padding-left:20px">地区</span>
        </template>
        <template slot-scope="scope">
          <span style="padding-left:20px">{{scope.row.city}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="yjNum"
        label="预警数量">
      </el-table-column>
      <el-table-column
        prop="bjNum"
        label="报警数量">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import VTable from "@/components/VTable/index";
import formTitleVue from "@/components/FormTitle/formTitle.vue";
import { time_select_optios } from '@/utils/global.js';
import { areaAlarmWarnList } from '@/api/alarm/statistics'

export default {
  name: "cityAlarmTable",
  components: {
    VTable,
    formTitleVue,
  },
  data() {
    return {
      tableData: [],
      selectOptions: [
        {
          selectValue: "近一月",
          options:[
            { label: "近一月", value: "近一月" },
            { label: "近半年", value: "近半年" },
            { label: "近一年", value: "近一年" },
          ],
          changeFn: this.selectChange2,
        }
      ],
      tableData: [],
      loading: false,
      searChForm: {
        startTime: '',
        endTime: '',
      },
    };
  },
  methods: {
    selectChange2(item){
      this.searChForm.startTime = time_select_optios[item].startTime
      this.searChForm.endTime = time_select_optios[item].endTime
      this.getData()
    },
    init(){
      this.searChForm.startTime = time_select_optios[this.selectOptions[0].selectValue].startTime
      this.searChForm.endTime = time_select_optios[this.selectOptions[0].selectValue].endTime
      this.getData()
    },
    getData() {
      let params ={
        startTime:this.searChForm.startTime+" 00:00:00",
        endTime:this.searChForm.endTime+" 23:59:59",
        areaCode:this.$store.state.account.user.deptIds,
        placeType:this.$commonJs.getPlaceType(this.$store.state.account.user.deptIds)
      }
      areaAlarmWarnList(params).then(res=>{
          if(res.code==200){
            this.tableData = res.data
          }
      })
      // ============================
      // console.log(this.searChForm)
      // this.tableData = [
      //   {
      //     month: "2023-09",
      //     city: "广州市",
      //     yjnum: "20",
      //     bjnum: "35"
      //   },
      //   {
      //     month: "2023-09",
      //     city: "深圳市",
      //     yjnum: "22",
      //     bjnum: "41"
      //   },
      //   {
      //     month: "2023-09",
      //     city: "珠海市",
      //     yjnum: "20",
      //     bjnum: "36"
      //   },
      //   {
      //     month: "2023-09",
      //     city: "汕头市",
      //     yjnum: "19",
      //     bjnum: "40"
      //   },
      // ];
    },
  },
  mounted() {
    this.init()
  },
};
</script>

<style lang="scss" scoped>
.cityAlarmTable-root {

}
</style>
